package com.knight.spring;

import com.knight.spring.bean.*;
import org.springframework.beans.factory.support.BeanDefinitionReader;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.xml.BeanDefinitionDocumentReader;
import org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader;
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;

import java.util.ArrayList;
import java.util.List;

public class SpringClient {
    public static void main(String[] args) {

        Resource resource = new ClassPathResource("applicationContext.xml");

        DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();

        BeanDefinitionReader beanDefinitionReader = new XmlBeanDefinitionReader(beanFactory);

        int num = beanDefinitionReader.loadBeanDefinitions(resource);
        System.out.println(num);


        Tire tire = beanFactory.getBean("tire", Tire.class);
        Tire tire2 = beanFactory.getBean("tire", Tire.class);
        Car car = beanFactory.getBean("car", Car.class);
        System.out.println(tire);
        System.out.println(car);
        ConstructBean constructBean = beanFactory.getBean("constructBean", ConstructBean.class);
        Student student = beanFactory.getBean("student", Student.class);
        Student student1 = beanFactory.getBean("student", Student.class);
        System.out.println(student);
        System.out.println("------------------------------");

        Test1 test1 = beanFactory.getBean("test1", Test1.class);
        beanFactory.getBean("test1", Test1.class);
        Test2 test2 = beanFactory.getBean("test2", Test2.class);

    }


}
